//
//  SearchResultCell.m
//  ImGuider
//
//  Created by 王鹏宇 on 2018/5/22.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "SearchResultCell.h"
@interface SearchResultCell()

@property (nonatomic, strong) UIButton * deleteBtn;

@end

@implementation SearchResultCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.deleteBtn];
        [self.deleteBtn setImage:[UIImage imageNamed:@"close_black"] forState:UIControlStateNormal];
        [self.deleteBtn addTarget:self action:@selector(delete) forControlEvents:UIControlEventTouchUpInside];
        [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self.contentView.mas_trailing).offset(-10);
            make.bottom.equalTo(self.contentView.mas_bottom);
            make.top.equalTo(self.contentView.mas_top);
            make.width.mas_equalTo(40);
        }];
        
        
        self.textLabel.textColor = kTitleColor;
        self.textLabel.font = Font(14);
        self.detailTextLabel.textColor = kContentColor;
        self.detailTextLabel.font = Font(12);
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return self;
}


- (void)configDataWith:(SearchResultModel *)model Index:(NSInteger)index {
    self.index = index;
    self.textLabel.text  = model.title;
    self.detailTextLabel.text = model.desc;
    
    
    if ([model.type isEqualToString:@"city"]) {
        self.imageView.image = [UIImage imageNamed:@"position"];
    }else if([model.type isEqualToString:@"view"]){
        self.imageView.image = [UIImage imageNamed:@"searchView"];
    }
}


- (void)delete {
    
    if (_delegate ) {
        [_delegate deleteTheIndex:self.index];
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
